cmake_minimum_required(VERSION 3.6)

# 设置编译标志位 增加了 -fPIC
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC -Wall")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC -Wall")

set(CMAKE_CXX_STANDARD 14)

project(OrionV2)

set(CMAKE_BUILD_TYPE DEBUG)

option(ENABLE_DEMO "this option for enable demo" ON)
option(ENABLE_LOG "this option for enable log" ON)

find_package(OpenSSL 1.0.2 REQUIRED COMPONENTS ssl crypto)
find_package(Boost 1.64.0 REQUIRED COMPONENTS context system thread fiber)

if (ENABLE_DEMO)
    add_subdirectory(Demo)
endif ()

if (APPLE)
    add_definitions(-DOSX)
elseif (LINUX)
    add_definitions(-DLINUX)
endif ()

if (ENABLE_LOG)
    add_definitions(-DENABLE_LOG)
endif ()

include_directories(
        Concurrent/
        AsyncIO/
        Coroutine/
        Traits/
        Utils/
        .
)
include_directories(${Boost_INCLUDE_DIRS})

set(COROUTINE_HEADER
        Coroutine/CoroutineCore.h
        Coroutine/Coroutine.h
        )
set(COROUTINE_SRC
        Coroutine/CoroutineCore.cpp
        Coroutine/Coroutine.cpp
        )

set(HEADER_FILES
        ${COROUTINE_HEADER}
        Orion.h
        Concurrent/FutureAdapt.hpp
        AsyncIO/AsyncEventGenerator.h
        AsyncIO/CountDownLath.h
        Utils/Utils.h
        AsyncIO/AsyncEventGeneratorGroup.h
        AsyncIO/HttpResponse.h
        AsyncIO/HttpRequest.h
        AsyncIO/FileStream.h
        AsyncIO/AbstractAsyncStream.h
        AsyncIO/IOBuffer.h
        AsyncIO/IOBehavior.h
        AsyncIO/SocketIO.h
        AsyncIO/SocketAcceptor.h
        Traits/Traits.hpp
        AsyncIO/BasicEventGenerator.h
        )

set(SOURCE_FILES
        ${COROUTINE_SRC}
        Orion.cpp
        AsyncIO/AsyncEventGenerator.cpp
        AsyncIO/CountDownLath.cpp
        Utils/Utils.cpp
        AsyncIO/AsyncEventGeneratorGroup.cpp
        AsyncIO/HttpResponse.cpp
        AsyncIO/HttpRequest.cpp
        AsyncIO/FileStream.cpp
        AsyncIO/AbstractAsyncStream.cpp
        AsyncIO/IOBuffer.cpp
        AsyncIO/IOBehavior.cpp
        AsyncIO/SocketAcceptor.cpp
        AsyncIO/SocketIO.cpp
        AsyncIO/BasicEventGenerator.cpp
        )

add_library(OrionV2 SHARED ${HEADER_FILES} ${SOURCE_FILES})

target_link_libraries(OrionV2 LINK_PUBLIC pthread)

target_link_libraries(OrionV2 LINK_PUBLIC ${OPENSSL_LIBRARIES})
target_link_libraries(OrionV2 LINK_PUBLIC ${Boost_LIBRARIES})

target_link_libraries(OrionV2 LINK_PUBLIC uv)
target_link_libraries(OrionV2 LINK_PUBLIC glog)
target_link_libraries(OrionV2 LINK_PUBLIC http_parser)


install(TARGETS OrionV2 LIBRARY DESTINATION /usr/local/lib
        PERMISSIONS OWNER_EXECUTE OWNER_WRITE OWNER_READ GROUP_EXECUTE GROUP_READ WORLD_READ WORLD_EXECUTE)

install(FILES ${HEADER_FILES} DESTINATION /usr/local/include/OrionV2)



